﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{
    [Table(Name = "dbo.BJ")]
    public class BJ : Entity
    {
        private decimal _bjNum;

        private decimal _zyNum;

        private decimal _zgId;

        private string _bjName;

        private bool _bjZF;

        private EntitySet<XS> _XS;

        private EntityRef<ZY> _ZY;

        private EntityRef<ZG> _ZG;

        

        public BJ()
        {
            this._XS = new EntitySet<XS>(new Action<XS>(this.attach_XS), new Action<XS>(this.detach_XS));
            this._ZY = default(EntityRef<ZY>);
            this._ZG = default(EntityRef<ZG>);
        }

        [Column(Storage = "_bjNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal BJNum
        {
            get
            {
                return this._bjNum;
            }
            set
            {
                if ((this._bjNum != value))
                {
                    this.SendPropertyChanging("BJNum");
                    this._bjNum = value;
                    this.SendPropertyChanged("BJNum",value);
                }
            }
        }

        [Column(Storage = "_zyNum", DbType = "Decimal(18,0)")]
        public decimal ZYNum
        {
            get
            {
                return this._zyNum;
            }
            set
            {
                if ((this._zyNum != value))
                {
                    if (this._ZY.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("ZYNum");
                    this._zyNum = value;
                    this.SendPropertyChanged("ZYNum",value);
                }
            }
        }

        [Column(Storage = "_zgId", DbType = "Decimal(18,0)")]
        public decimal ZGId
        {
            get
            {
                return this._zgId;
            }
            set
            {
                if ((this._zgId != value))
                {
                    if (this._ZG.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("ZGId");
                    this._zgId = value;
                    this.SendPropertyChanged("ZGId",value);
                }
            }
        }

        [Column(Storage = "_bjName", DbType = "VarChar(30) NOT NULL", CanBeNull = false)]
        public string BJName
        {
            get
            {
                return this._bjName;
            }
            set
            {
                if ((this._bjName != value))
                {
                    this.SendPropertyChanging("BJName");
                    this._bjName = value;
                    this.SendPropertyChanged("BJName",value);
                }
            }
        }

        [Column(Storage = "_bjZF", DbType = "Bit")]
        public bool BJZF
        {
            get
            {
                return this._bjZF;
            }
            set
            {
                if ((this._bjZF != value))
                {
                    this.SendPropertyChanging("BJZF");
                    this._bjZF = value;
                    this.SendPropertyChanged("BJZF",value);
                }
            }
        }

        [Association(Name = "BJ_XS", Storage = "_XS", ThisKey = "BJNum", OtherKey = "BJNum")]
        public EntitySet<XS> XS
        {
            get
            {
                return this._XS;
            }
            set
            {
                this._XS.Assign(value);
            }
        }

        [Association(Name = "ZY_BJ", Storage = "_ZY", ThisKey = "ZYNum", OtherKey = "ZYNum", IsForeignKey = true)]
        public ZY ZY
        {
            get
            {
                return this._ZY.Entity;
            }
            set
            {
                ZY previousValue = this._ZY.Entity;
                if (((previousValue != value)
                            || (this._ZY.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("ZY");
                    if ((previousValue != null))
                    {
                        this._ZY.Entity = null;
                        previousValue.BJ.Remove(this);
                    }
                    this._ZY.Entity = value;
                    if ((value != null))
                    {
                        value.BJ.Add(this);
                        this._zyNum = value.ZYNum;
                    }
                    else
                    {
                        this._zyNum = default(decimal);
                    }
                    this.SendPropertyChanged("ZY",value);
                }
            }
        }

        [Association(Name = "ZG_BJ", Storage = "_ZG", ThisKey = "ZGId", OtherKey = "ZGId", IsForeignKey = true)]
        public ZG ZG
        {
            get
            {
                return this._ZG.Entity;
            }
            set
            {
                ZG previousValue = this._ZG.Entity;
                if (((previousValue != value)
                            || (this._ZG.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("ZG");
                    if ((previousValue != null))
                    {
                        this._ZG.Entity = null;
                        previousValue.BJ.Remove(this);
                    }
                    this._ZG.Entity = value;
                    if ((value != null))
                    {
                        value.BJ.Add(this);
                        this._zgId = value.ZGId;
                    }
                    else
                    {
                        this._zgId = default(decimal);
                    }
                    this.SendPropertyChanged("ZG",value);
                }
            }
        }

        private void attach_XS(XS entity)
        {
            entity.BJ = this;
        }

        private void detach_XS(XS entity)
        {
            entity.BJ = null;
        }
    }
}
